﻿using System.Xml.Linq;
using FarseerGames.FarseerPhysics.Mathematics;
using FreeGoo.GameEngine;
using FreeGoo.GameEngine.Renderables;

namespace FreeGoo.LevelClasses.LevelParts
{
    public class RectangleLevelPart : BodyRenderableLevelPart
    {
        public override string Name { get { return "Rectangle"; } }
        public override BodyRenderable BuildBodyRenderable(Level level, XElement element)
        {
            /* Example Xml:
             * <Rectangle Position="550,500" Size="30,200" Rotation="0" IsStatic="true" >
             *   <Surface IsDeadly="true"/>
             * </Rectangle>
             */

            BodyRenderable rectangle;
            Vector2 position = GetOffsetPosition(level, element);
            Vector2 size = element.Attribute("Size").ToVector2();
            float angle = ConvertDegreesToRadians(element.Attribute("Rotation").ToFloat());
            float density = element.Attribute("Density").ToFloat(100.0f) / 100.0f;

            rectangle = MixedFactory.CreateRectangle(
                level.Engine,
                position,
                size,
                density,
                angle);
            
            return rectangle;
        }       
    }
}
